﻿using MediatR;
using S.Authorization.Common.Dto;
using S.Authorization.Domain.Model.Organization;
using S.Authorization.Domain.Model.User;
using S.Authorization.Infrastructure.Interface.User;
using S.Authorization.Read.API.Application.Command.UserCommand;

namespace S.Authorization.Read.API.Application.CommandHandlers.UserCommandHandler
{
    public class UserSelectCommandHandler : IRequestHandler<UserSelectCommand, List<SelectDto>>
    {
        private readonly IUserModellRepository user;
        public UserSelectCommandHandler(IUserModellRepository _user)
        {
            this.user = _user;
        }
        /// <summary>
        /// 用户下拉框显示
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<List<SelectDto>> Handle(UserSelectCommand request, CancellationToken cancellationToken)
        {
            List<UsersModel> childList = user.GetAllAsync().Result;
            List<SelectDto> children = childList.Select(x => new SelectDto
            {
                value = x.UserId,
                label = x.UserTrueName,
            }).ToList();
            return children;
        }
    }
}
